package com.sslite.model;

import java.util.Map;
import java.util.TreeMap;

public class ChartApplet {
	final private Map<String, String> paramValues = new TreeMap<String, String>();
	private String appletName;
	private int width;
	private int height;
	
	public ChartApplet(String appletName, int width, int height) {
		this.appletName = appletName;
		this.width = width;
		this.height = height;
		
		paramValues.put("zoomon", "true");
		paramValues.put("chart", "line");
		paramValues.put("seriesRange_0", "2");
		paramValues.put("sampleLabelsOn", "true");
		paramValues.put("sampleLabelStyle", "floating");
		paramValues.put("floatingLabelFont", "Verdana, plain, 10");
		paramValues.put("sampleColors", "blue, red");
		paramValues.put("sampleHighlightOn", "true");
		paramValues.put("sampleHighlightStyle", "circle_opaque");
		paramValues.put("sampleHighlightSize", "6");
		paramValues.put("rangeColor", "red");
		paramValues.put("rangeColor_2", "blue");
		paramValues.put("seriesCount", "2");
		paramValues.put("valueLabelsOn", "true");
		paramValues.put("valueLabelStyle", "floating");
		paramValues.put("valueLinesOn", "true");
		paramValues.put("defaultGridLinesOn", "true");
		paramValues.put("legendOn", "true");
		paramValues.put("legendPosition", "top");
		paramValues.put("legendLabels", "Close,Volume");
		paramValues.put("rangeOn_2", "true");
		paramValues.put("rangePosition", "right");
		paramValues.put("rangePosition_2", "left");
		paramValues.put("rangeAxisLabel", "Volume");
		paramValues.put("rangeAxisLabelFont", "Verdana, bold, 16");
		paramValues.put("rangeAxisLabelAngle", "90");
		paramValues.put("rangeAxisLabel_2", "Close");
		paramValues.put("rangeAxisLabelAngle_2", "270");
		paramValues.put("rangeLabelPrefix_2", "$");
		paramValues.put("multiSeriesOn", "true");
		paramValues.put("rangeDecimalCount", "0");
		paramValues.put("rangeDecimalCount_2", "2");
		paramValues.put("sampleDecimalCount", "2");
		paramValues.put("sampleDecimalCount_2", "0");
		paramValues.put("chartBackground", "#DADAFF");

		paramValues.put("chartTitle", "~SYMBOL");
		paramValues.put("sampleValues_0", "~CLOSE_DATA");
		paramValues.put("sampleValues_1", "~VOLUME_DATA");
		paramValues.put("sampleLabels", "~DATES_DATA");
	}
	
	public void setParamValue(String param, String value){
		paramValues.put(param, value);
	}
	
	public String getChartAppletHTML(){
		final StringBuilder sb = new StringBuilder();
		
		sb.append("<applet name='").append( this.appletName ).append("' code='com.objectplanet.chart.ChartApplet' archive='chart.jar' width='").append(this.width).append("' height='").append( this.height ).append("'>\n");
		for(final String key : this.paramValues.keySet()){
			sb.append( "<param name='" ).append( key ).append( "' value='" ).append( this.paramValues.get(key) ).append("'>\n");
		}
		sb.append("</applet>\n");
		
		return sb.toString();
	}
	
}
